<UserControl x:Uid="UserControl_1" x:Class="Adastra.RichEditorLibrary.ColorPick"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Adastra.RichEditorLibrary"
     xmlns:properties="clr-namespace:Adastra.RichEditorLibrary.Properties"
    Background="#FF808080" >

    <UserControl.Resources>

        <local:PreviewColorConverter x:Uid="local:PreviewColorConverter_1" x:Key="PreviewColConv"/>
        <local:ColorToPointerConverter x:Uid="local:ColorToPointerConverter_1" x:Key="ColPointConv"/>
        <local:ColorToRainbowPointerConverter x:Uid="local:ColorToRainbowPointerConverter_1" x:Key="ColRPointConv"/>
        <local:DoubleToByteConverter x:Uid="local:DoubleToByteConverter_1" x:Key="DoubleByteConv"/>
        <local:ColorToBrushConverter x:Uid="local:ColorToBrushConverter_1" x:Key="ColBrConv"/>
        <local:ColorToHexConverter x:Uid="local:ColorToHexConverter_1" x:Key="ColHexConv"/>

        <Style x:Uid="Style_1" TargetType="{x:Type UserControl}" x:Key="ControlStyle1">
            <Setter x:Uid="Setter_1" Property="Padding" Value="2,2,2,2"/>
            <Setter x:Uid="Setter_2" Property="BorderThickness" Value="0"/>
            <Setter x:Uid="Setter_3" Property="Template">
                <Setter.Value>
                    <ControlTemplate x:Uid="ControlTemplate_1" TargetType="{x:Type UserControl}">
                        <Grid x:Uid="Grid_1" ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local">
                            <Grid.RowDefinitions>
                                <RowDefinition x:Uid="RowDefinition0" Height="Auto" x:Name="RowDefinition0"/>
                                <RowDefinition x:Uid="RowDefinition1" Height="*" x:Name="RowDefinition1"/>
                            </Grid.RowDefinitions>
                            <TabPanel x:Uid="HeaderPanel" x:Name="HeaderPanel" Grid.Row="0" IsItemsHost="true" Panel.ZIndex="1" KeyboardNavigation.TabIndex="1"/>
                            <Border x:Uid="ContentPanel" x:Name="ContentPanel" Grid.Row="1" Background="{TemplateBinding Background}" 
                                    BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" 
                                    KeyboardNavigation.DirectionalNavigation="Contained" KeyboardNavigation.TabIndex="2" 
                                    KeyboardNavigation.TabNavigation="Local">
                                <ContentPresenter x:Uid="PART_SelectedContentHost" Margin="{TemplateBinding Padding}" x:Name="PART_SelectedContentHost" 
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="SelectedContent"/>
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Uid="Style_2" TargetType="{x:Type TabItem}">
            <Setter x:Uid="Setter_4" Property="Template">
                <Setter.Value>
                    <ControlTemplate x:Uid="ControlTemplate_2" TargetType="{x:Type TabItem}">
                        <Grid x:Uid="Grid_2">
                            <Border 
        		                x:Uid="Border" x:Name="Border"
        		                CornerRadius="6,6,0,0"
        		                Margin="0,0,0,0"
        		                Width="125" Height="20">
                                <ContentPresenter x:Uid="ContentSite" x:Name="ContentSite"
        			                VerticalAlignment="Center"
        			                ContentSource="Header"
        			                Margin="6,2,6,2" HorizontalAlignment="Left"/>
                            </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger x:Uid="Trigger_1" Property="IsSelected" Value="True">
                                <Setter x:Uid="Setter_5" TargetName="Border" 
                                    Property="Background" Value="#FF808080" />
                            </Trigger>
                            <Trigger x:Uid="Trigger_2" Property="IsSelected" Value="False">
                                <Setter x:Uid="Setter_6" TargetName="Border" 
                                    Property="Background" Value="#FF2D2D2D" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <DataTemplate x:Uid="DataTemplate_1" x:Key="ColorItem">
            <DockPanel x:Uid="DockPanel_1" LastChildFill="True" Height="18">
                <Rectangle x:Uid="Rectangle_1" Height="15" DockPanel.Dock="Left" Fill="{Binding Name, Mode=OneTime}" 
                                       Width="40" Stroke="Black"/>
                <TextBlock x:Uid="TextBlock_1" Height="18" DockPanel.Dock="Left" Margin="3,2,5,0" Width="110"
                                       Foreground="Black" FontSize="11" Text="{Binding Name, Mode=OneTime}"/>
                <TextBlock x:Uid="TextBlock_2" Height="18" DockPanel.Dock="Left" Margin="3,3,0,0" FontFamily="Courier New" FontWeight="Bold"
                                       Foreground="Black" FontSize="11" Text="{Binding Name, Converter={StaticResource ColHexConv}, Mode=OneTime}"/>
            </DockPanel>
        </DataTemplate>

    </UserControl.Resources>

    <Grid x:Uid="Grid_3">
        <Grid x:Uid="Grid_4">
            <Grid.RowDefinitions>
                <RowDefinition x:Uid="RowDefinition_1" Height="24"/>
                <RowDefinition x:Uid="RowDefinition_2"/>
            </Grid.RowDefinitions>
            <StackPanel x:Uid="StackPanel_1" Grid.Row="0" Orientation="Horizontal">
                <Button x:Uid="Button_1" Content="{x:Static properties:Resources.ColorPick_Button_1_Content}" HorizontalAlignment="Left" Width="auto" Click="OnAutomaticButtonClick" Margin="2,2,2,2"/>
                <ComboBox x:Uid="m_cbxColorsBox" x:Name="m_cbxColorsBox" Margin="0,0,0,0" Height="24"  SelectionChanged="ColorsBox_SelectionChanged" HorizontalAlignment="Left" VerticalAlignment="Stretch"
                          IsSynchronizedWithCurrentItem="True" ItemTemplate="{DynamicResource ColorItem}" />
            </StackPanel>

            <Grid x:Uid="Grid_5" Grid.Row="1" ClipToBounds="True">
                <Grid.RowDefinitions>
                    <RowDefinition x:Uid="RowDefinition_3" Height="0.25*"/>
                    <RowDefinition x:Uid="RowDefinition_4" Height="0.25*"/>
                    <RowDefinition x:Uid="RowDefinition_5" Height="0.25*"/>
                    <RowDefinition x:Uid="RowDefinition_6" Height="0.25*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition x:Uid="ColumnDefinition_1" Width="120"/>
                    <ColumnDefinition x:Uid="ColumnDefinition_2" Width="15"/>
                    <ColumnDefinition x:Uid="ColumnDefinition_3" Width="0.07*"/>
                    <ColumnDefinition x:Uid="ColumnDefinition_4" Width="0.35*"/>
                </Grid.ColumnDefinitions>
                <Rectangle x:Uid="ColorLayer" x:Name="ColorLayer" Grid.RowSpan="4">
                    <Rectangle.Fill>
                        <LinearGradientBrush x:Uid="LinearGradientBrush_1" EndPoint="1,0" StartPoint="0,0">
                            <GradientStop x:Uid="GradientStop_1" Color="#FFFFFFFF" Offset="0"/>
                            <GradientStop x:Uid="PreviewColor" x:Name="PreviewColor" Offset="1"
                                Color="{Binding Color, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource PreviewColConv}}"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
                <Rectangle x:Uid="BWLayer" Stroke="#FF333333" x:Name="BWLayer" Grid.RowSpan="4" Cursor="Cross"
                    MouseDown="BWLayer_MouseDown" MouseMove="BWLayer_MouseMove" MouseUp="BWLayer_MouseUp">
                    <Rectangle.Fill>
                        <LinearGradientBrush x:Uid="LinearGradientBrush_2" EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop x:Uid="GradientStop_2" Color="#FF000000" Offset="1"/>
                            <GradientStop x:Uid="GradientStop_3" Color="#00000000" Offset="0"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
                <Ellipse x:Uid="ColorPointer" x:Name="ColorPointer" Width="9" Height="9" Grid.RowSpan="4" StrokeThickness="2"
                    HorizontalAlignment="Left" VerticalAlignment="Top" IsHitTestVisible="False"
                    Margin="{Binding Color, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource ColPointConv}}">
                    <Ellipse.Stroke>
                        <RadialGradientBrush x:Uid="RadialGradientBrush_1">
                            <GradientStop x:Uid="GradientStop_4" Color="#FF000000" Offset="0.75"/>
                            <GradientStop x:Uid="GradientStop_5" Color="#FFFFFFFF" Offset="1"/>
                        </RadialGradientBrush>
                    </Ellipse.Stroke>
                </Ellipse>
                <Rectangle x:Uid="Rainbow" x:Name="Rainbow" Stroke="#FF333333" Grid.Column="1" Grid.RowSpan="4" Margin="-1,0,0,0"
                    MouseDown="Rainbow_MouseDown" MouseMove="Rainbow_MouseMove" MouseUp="Rainbow_MouseUp">
                    <Rectangle.Fill>
                        <LinearGradientBrush x:Uid="LinearGradientBrush_3" EndPoint="0,1" StartPoint="0,0">
                            <GradientStop x:Uid="GradientStop_6" Color="#FFFF0000" Offset="0"/>
                            <GradientStop x:Uid="GradientStop_7" Color="#FFFFFF00" Offset="0.167"/>
                            <GradientStop x:Uid="GradientStop_8" Color="#FF00FF00" Offset="0.333"/>
                            <GradientStop x:Uid="GradientStop_9" Color="#FF00FFFF" Offset="0.5"/>
                            <GradientStop x:Uid="GradientStop_10" Color="#FF0000FF" Offset="0.667"/>
                            <GradientStop x:Uid="GradientStop_11" Color="#FFFF00FF" Offset="0.833"/>
                            <GradientStop x:Uid="GradientStop_12" Color="#FFFF0000" Offset="1"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
                <Rectangle x:Uid="RainbowPointer" x:Name="RainbowPointer" Stroke="#FF000000" Grid.Column="1" Grid.RowSpan="4" Height="4" 
                    RadiusX="2" RadiusY="2" VerticalAlignment="Top" IsHitTestVisible="False"
                    Margin="{Binding Color, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource ColRPointConv}}"/>
                <Slider x:Uid="R" x:Name="R" Grid.Column="3" VerticalAlignment="Center" 
                        Maximum="255" SmallChange="1" Value="255" />
                <TextBlock x:Uid="Rtext" x:Name="Rtext" Background="#00000000" Foreground="#FFFF0000" Grid.Column="2" Grid.Row="0" 
                        Text="R" TextAlignment="Center" VerticalAlignment="Top" FontWeight="Bold"/>
                <TextBlock x:Uid="Rvalue" x:Name="Rvalue" Background="#00000000" Foreground="#FF333333" Grid.Column="2" Grid.Row="0"
                        Text="{Binding Value, ElementName=R, Converter={StaticResource DoubleByteConv}}" 
					    TextAlignment="Center" VerticalAlignment="Bottom" FontWeight="Bold" Height="12"  FontSize="8"/>

                <Slider x:Uid="G" x:Name="G" Background="#007B8CA6" Grid.Column="3" VerticalAlignment="Center"
                         Maximum="255" SmallChange="1" Value="0" Grid.Row="1" />
                <TextBlock x:Uid="Gtext" x:Name="Gtext" Background="#00000000" Foreground="#FF00FF00" Grid.Column="2" Grid.Row="1" 
                         Text="G" TextAlignment="Center" VerticalAlignment="Top" FontWeight="Bold"/>
                <TextBlock x:Uid="Gvalue" x:Name="Gvalue" Background="#00000000" Foreground="#FF333333" Grid.Column="2" Grid.Row="1"
                        Text="{Binding Value, ElementName=G, Converter={StaticResource DoubleByteConv}}"
					    TextAlignment="Center" VerticalAlignment="Bottom" FontWeight="Bold" Height="12"  FontSize="8" />

                <Slider x:Uid="B" x:Name="B" Background="#007B8CA6" Grid.Column="3" VerticalAlignment="Center"
                         Maximum="255" SmallChange="1" Value="0" Grid.Row="2" />
                <TextBlock x:Uid="Btext" x:Name="Btext" Background="#00000000" Foreground="#FF0000FF" Grid.Column="2" Grid.Row="2" 
                         Text="B" TextAlignment="Center" VerticalAlignment="Top" FontWeight="Bold"/>
                <TextBlock x:Uid="Bvalue" x:Name="Bvalue" Background="#00000000" Foreground="#FF333333" Grid.Column="2" Grid.Row="2"
                        Text="{Binding Value, ElementName=B, Converter={StaticResource DoubleByteConv}}" 
					    TextAlignment="Center" VerticalAlignment="Bottom" FontWeight="Bold" Height="12"  FontSize="8" />

                <TextBox x:Uid="ColorHex" x:Name="ColorHex" Width="60" Background="#FF333333" Foreground="#FFFFFFFF" BorderBrush="{x:Null}"  
                         HorizontalAlignment="Left" Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="2"
                          TextAlignment="Center" Margin="5,7,0,7" FontFamily="Courier New" MaxLength="6">
                    <Binding x:Uid="Binding_1" Converter="{StaticResource ColHexConv}" UpdateSourceTrigger="PropertyChanged"
                		RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="Color">
                    </Binding>
                </TextBox>
                <Rectangle x:Uid="PreviewRectangle" x:Name="PreviewRectangle" Width="30" Height="30" Grid.Column="2" Grid.Row="3" 
                    Grid.ColumnSpan="2" HorizontalAlignment="Right" Stroke="#FF333333"
                    Fill="{Binding Color, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource ColBrConv}}">
                </Rectangle>
            </Grid>
        </Grid>
    </Grid>
</UserControl>
